<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller 
{
    private $_layoutDataArr = array();
    
    private $_fileLayout = 'layout/frontend/index';
 
    public function __construct()
    {
        parent::__construct();
        
        $this->load->helper('debug');
        $this->output->enable_profiler(FALSE);
    }
    
    public function render(array $viewDataArr = array(), $template = '')
    {      
        if (!$template) {
            if (!empty($this->router->directory)) {
        	   $template = $this->router->directory;
        	}
        	$template .= $this->router->class . '/';
        	// Exception with controler add & edit, file view should name as form
        	if ($this->router->method == 'add' || $this->router->method == 'edit') {
        	    $template .= 'form';
        	} else {
                $template .= $this->router->method;
        	}
        }
        
        // Returning views as data
        $this->_layoutDataArr['content'] = $this->load->view($template, $viewDataArr, TRUE);
        
        $this->load->view($this->_fileLayout, $this->_layoutDataArr);
    }
    
    public function setLayout($fileLayout)
    {
        $this->_fileLayout = $fileLayout;
    }
}